/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bash.jcouture.util.swing;

import com.bash.compta.data.Compte;
import com.bash.compta.data.CreditLevel;
import com.bash.compta.data.Login;
import com.bash.compta.db4o.MagicData;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author bashizip
 */
public class UsersTableModel extends AbstractTableModel {

    private List<Login> data = MagicData.getAllObjects(Login.class);
    private String[] colones = {"Nom", "Login", "Mot de passe ", "credit","Actif"};

    public UsersTableModel() {
    }

    public int getRowCount() {
        return data.size();
    }

    public int getColumnCount() {
        return colones.length;
    }


    public Object getValueAt(int rowIndex, int columnIndex) {
        Login l = data.get(rowIndex);

        Object toReturn = null;

        switch (columnIndex) {
            case 0:
                toReturn = l.getName();
                break;
            case 1:
                toReturn = l.getUsername();
                break;
            case 2:

                toReturn = l.getPassword();
                break;
            case 3: toReturn=CreditLevel.getLibelle(l.getCredit_level());
               break;
            case 4:
                toReturn =l.isActif()?"oui":"non" ;
                break;

        }
        return toReturn;

    }




    @Override
    public String getColumnName(int column) {
        return colones[column];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }
}
